package com.infolab.aims.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.joda.time.LocalDate;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import com.infolab.aims.GlobalConstant;
import com.infolab.aims.common.SpecialMuLineToStringStyle;
import com.infolab.aims.common.bean.AbstractModelBean;
import com.infolab.aims.domain.asset.AssetModel;

@Entity
@Table(name="AMTB_VENDOR_ASSET")
public class VendorAsset extends AbstractModelBean implements Serializable {
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Integer vendorAssetId;
	
	@ManyToOne
	@JoinColumn(name="assetModelId")
	private AssetModel assetModel;
	
	@ManyToOne
	@JoinColumn(name="vendorId")
	private Vendor vendor;
	
	private Float unitPrice;
	
	private String purchaseOrderCode;
	
	private Date purchaseOrderDate;
	
	@Transient
	private boolean deleted;
	
	
	public String getAuditContentHead()
	{
		AssetModel model = assetModel;
		if(assetModel==null){
			model = new AssetModel();
		}
		return new ToStringBuilder(this,SpecialMuLineToStringStyle.SPECIAL_MULINE_STYLE)
			.append("Asset Model", (model.getAssetModelCode()!=null?model.getAssetModelCode():"") + " " + 
					(model.getAssetModelName()!=null?model.getAssetModelName():""))
			.append("Unit Price",unitPrice)
			.append("PO Number",purchaseOrderCode)
			.append("PO date", getPurchaseOrderDateToDisplay())
			.toString();
	}

	public Integer getVendorAssetId() {
		return vendorAssetId;
	}

	public void setVendorAssetId(Integer vendorAssetId) {
		this.vendorAssetId = vendorAssetId;
	}

	public AssetModel getAssetModel() {
		return assetModel;
	}

	public void setAssetModel(AssetModel assetModel) {
		this.assetModel = assetModel;
	}

	public Vendor getVendor() {
		return vendor;
	}

	public void setVendor(Vendor vendor) {
		this.vendor = vendor;
	}

	public Float getUnitPrice() {
		return unitPrice;
	}

	public void setUnitPrice(Float unitPrice) {
		this.unitPrice = unitPrice;
	}

	public String getPurchaseOrderCode() {
		return purchaseOrderCode;
	}

	public void setPurchaseOrderCode(String purchaseOrderCode) {
		this.purchaseOrderCode = purchaseOrderCode;
	}

	public Date getPurchaseOrderDate() {
		return purchaseOrderDate;
	}

	public void setPurchaseOrderDate(Date purchaseOrderDate) {
		this.purchaseOrderDate = purchaseOrderDate;
	}

	public boolean isDeleted() {
		return deleted;
	}

	public void setDeleted(boolean deleted) {
		this.deleted = deleted;
	}
	

	public String getPurchaseOrderDateToDisplay()
	{
		DateTimeFormatter fmt = DateTimeFormat.forPattern(GlobalConstant.DATE_FORMAT_JAVA);
		
		if(purchaseOrderDate!=null) return new LocalDate(purchaseOrderDate.getTime()).toString(fmt);
				
		return "";
	}
}
